<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>组织机构信息</title>
<%@ include file="/common/header/meta.jsp"%>
<%@ include file="/common/header/script.jsp"%>
<script type="text/javascript">
	var $t1, $t2 ;
	$(function() {
		$t1 = $("#t1").tree({
			url: $tools.basePath+"/hrmgr/companyAction/treegrid.do",
			method: "get",animate: true, lines: true, 
			toggleOnClick: true, selectOnContextMenu: true, smooth: false, showOption: true,
            onClick: function (node) {
           	 	$.easyui.loading({ msg: "正在加载...", locale: "#centerPanel" });
            	$.post($tools.basePath+"/hrmgr/companyAction/get.do", {id:node.id}, function(result) {
            		if (result.id != undefined) {
            			$("#company_info").show() ;
            			$("#dept_info").hide() ;
            			$.each(result, function(name, val){
            				$("#company_info span[name="+name+"]").html(val) ;
            			});
            		}
            		$.easyui.loaded("#centerPanel");
				}, 'json').error(function(){$.easyui.loaded("#centerPanel");});
            },
            onLoadSuccess: function (node, data) {
            	$.easyui.loading({ msg: "正在加载...", locale: "#centerPanel" });
            	var node = $t1.tree("getRoot") ;
            	if(node) {
            		$t1.tree("select", node.target) ;
                	$.post($tools.basePath+"/hrmgr/companyAction/get.do", {id:node.id}, function(result) {
                		if (result.id != undefined) {
                			$("#company_info").show() ;
                			$("#dept_info").hide() ;
                			$.each(result, function(name, val){
                				$("#company_info span[name="+name+"]").html(val) ;
                			});
                		}
                		$.easyui.loaded("#centerPanel");
    				}, 'json').error(function(){$.easyui.loaded("#centerPanel");});
                	
                	$t2 = $("#t2").tree({
            			url: $tools.basePath+"/hrmgr/deptAction/treegrid.do?company_id="+node.id,
            			method: "get",animate: true, lines: true, 
            			toggleOnClick: true, selectOnContextMenu: true, smooth: false, showOption: true,
                        onClick: function (node) {
                        	$.easyui.loading({ msg: "正在加载...", locale: "#centerPanel" });
                        	$.post($tools.basePath+"/hrmgr/deptAction/get.do", {id:node.id}, function(result) {
                        		if (result.id != undefined) {
    		                    	$("#company_info").hide() ;
    		                    	$("#dept_info").show() ;
                        			$.each(result, function(name, val){
                        				$("#dept_info span[name="+name+"]").html(val) ;
                        			});
                        		}
                        		$.easyui.loaded("#centerPanel");
            				}, 'json').error(function(){$.easyui.loaded("#centerPanel");});
                        }
            	    });
            	} else { $.easyui.loaded("#centerPanel"); }
            }
	    });
		
	});	
	
	function company_form_edit(form) {
		var form_url = $tools.basePath+"/hrmgr/companyAction/company_form.do" ;
		if("E" == form) {
			var node = $t1.tree('getSelected');
			if (node) {
				form_url = $tools.basePath+"/hrmgr/companyAction/company_form.do?id="+node.id ;
			} else {
				alertify.warning("请选择一条记录！");
				return ;
			}
		}
		var $d = $.easyui.showDialog({
			href: form_url,
            title: "表单", iniframe: false, width: 750, height: 270, topMost: true,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '保存', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $t1) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function company_del() {
		var node = $t1.tree('getSelected'); 
		if(node){
			$.messager.confirm("您确定要进行该操作？<br/>该删除操作会将子菜单一并删除。", function (c) { 
				if(c) {
					$.post($tools.basePath+"/hrmgr/companyAction/delete.do", {id:node.id}, function(result) {
						if (result.status) {
							$t1.tree('reload') ;
							alertify.success(result.msg);
						} else {
							alertify.error(result.msg);
						}
					}, 'json');
				}
			});
		} else {
			alertify.warning("请选择一条记录！");
		}
	}
	
	function dept_form_edit(form) {
		var form_url = $tools.basePath+"/hrmgr/deptAction/dept_form.do" ;
		if("E" == form) {
			var node = $t2.tree('getSelected');
			if (node) {
				form_url = $tools.basePath+"/hrmgr/deptAction/dept_form.do?id="+node.id ;
			} else {
				alertify.warning("请选择一条记录！");
				return ;
			}
		}
		var $d = $.easyui.showDialog({
			href: form_url,
            title: "表单", iniframe: false, width: 750, height: 563, topMost: true,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '保存', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $t2) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function dept_del() {
		var node = $t2.tree('getSelected'); 
		if(node){
			$.messager.confirm("您确定要进行该操作？<br/>该删除操作会将子菜单一并删除。", function (c) { 
				if(c) {
					$.post($tools.basePath+"/hrmgr/deptAction/delete.do", {id:node.id}, function(result) {
						if (result.status) {
							$t1.tree('reload') ;
							alertify.success(result.msg);
						} else {
							alertify.error(result.msg);
						}
					}, 'json');
				}
			});
		} else {
			alertify.warning("请选择一条记录！");
		}
	}
</script>

</head>

<body style="padding: 0px; margin: 0px;">
	<div class="easyui-layout" data-options="fit: true">
		
		<div data-options="region: 'west', border: false, iconCls: 'icon-standard-map', split: true, minWidth: 255, maxWidth: 500" style="width: 250px; padding: 1px;">
			<div class="easyui-layout" data-options="fit: true">
				<div data-options="region: 'center', title: '单位', split: true, border: true" style="height: 331px;">
					<div class="easyui-layout" data-options="fit: true">
                        <div data-options="region: 'north', split: false, border: false" style="height: 31px;">
                            <div class="easyui-toolbar">
                                <a id="navMenu_Favo" onClick="company_form_edit('A');" class="easyui-linkbutton easyui-tooltip" title="新建" data-options="plain: true, iconCls: 'ext_add'">新建</a>
                                <a id="navMenu_Rename" onClick="company_form_edit('E');" class="easyui-linkbutton easyui-tooltip" title="编辑" data-options="plain: true, iconCls: 'ext_edit'">编辑</a>
                                <a id="navMenu_Rename" onClick="company_del();" class="easyui-linkbutton easyui-tooltip" title="删除" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
                                <a id="navMenu_Rename" onClick="$t1.tree('reload');" class="easyui-linkbutton easyui-tooltip" title="刷新" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
                            </div>
                        </div>
                        <div data-options="region: 'center', border: false">
                            <ul id="t1" style="padding-top: 2px; padding-bottom: 2px;"></ul>
                        </div>
                    </div>
				</div>
				
				<div data-options="region: 'south', title: '部门', split: true, border: true, minHeight: 32, maxHeight: 370"  style="height: 370px;">
					<div class="easyui-layout" data-options="fit: true">
                        <div data-options="region: 'north', split: false, border: false" style="height: 31px;">
                            <div class="easyui-toolbar">
                                <a id="navMenu_Favo" onClick="dept_form_edit('A');" class="easyui-linkbutton easyui-tooltip" title="新建" data-options="plain: true, iconCls: 'ext_add'">新建</a>
                                <a id="navMenu_Rename" onClick="dept_form_edit('E');" class="easyui-linkbutton easyui-tooltip" title="编辑" data-options="plain: true, iconCls: 'ext_edit'">编辑</a>
                                <a id="navMenu_Rename" onClick="dept_del();" class="easyui-linkbutton easyui-tooltip" title="删除" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
                                <a id="navMenu_Rename" onClick="$t2.tree('reload');" class="easyui-linkbutton easyui-tooltip" title="刷新" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
                            </div>
                        </div>
                        <div data-options="region: 'center', border: false">
                            <ul id="t2" style="padding-top: 2px; padding-bottom: 2px;"></ul>
                        </div>
                    </div>
				</div>
			</div>
		</div>
		
		<div id="centerPanel" data-options="region: 'center', border: false" style="padding: 1px;">
		
			<div id="company_info">
				<table class="grid">
					<tr>
						<td>名称：</td>
						<td width="300"><span name="name"></span></td>
					</tr>
					<tr>
						<td>代码：</td>
						<td width="450"><span name="code"></span></td>
					</tr>
					<tr>
						<td>电话：</td>
						<td width="450"><span name="tel"></span></td>
					</tr>
					<tr>
						<td>传真：</td>
						<td width="450"><span name="fax"></span></td>
					</tr>
					<tr>
						<td>邮编：</td>
						<td width="300"><span name=""></span></td>
					</tr>
					<tr>
						<td>地址：</td>
						<td width="450"><span name=""></span></td>
					</tr>
					<tr>
						<td>网站：</td>
						<td width="450"><span name=""></span></td>
					</tr>
					<tr>
						<td>单位简介：</td>
						<td width="450"><span name=""></span></td>
					</tr>
				</table>
			</div>
			<div id="dept_info">
				<table class="grid">
					<tr>
						<td>部门：</td>
						<td width="300"><span name="name"></span></td>
					</tr>
					<tr>
						<td>部门主管：</td>
						<td width="450"><span name=""></span></td>
					</tr>
					<tr>
						<td>部门助理：</td>
						<td width="450"><span name=""></span></td>
					</tr>
					<tr>
						<td>分管领导：</td>
						<td width="300"><span name=""></span></td>
					</tr>
					<tr>
						<td>电话：</td>
						<td width="450"><span name="tel"></span></td>
					</tr>
					<tr>
						<td>传真：</td>
						<td width="450"><span name="fax"></span></td>
					</tr>
					<tr>
						<td>职能：</td>
						<td width="450"><span name=""></span></td>
					</tr>
					<tr>
						<td>传真：</td>
						<td width="450"><span name=""></span></td>
					</tr>
				</table> 
				<table class="grid" style="margin-top:10px;">
					<tr>
						<td>在职人员：</td>
						<td width="450"></td>
					</tr>
					<tr>
						<td>离职人员：</td>
						<td width="450"></td>
					</tr>
					<tr>
						<td>退休人员：</td>
						<td width="450"></td>
					</tr>
				</table>
				
			</div>
		
		</div>
		
	</div>	
</body>
</html>